<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>信息管理</title>
  {% load staticfiles %}
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
    <script src="/static/bootstrap/js/jquery.min.js"></script>
    <script src="/static/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>

<!-- 导航栏 -->
<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
    <div class="navbar-header">
        <a class="navbar-brand" href="#">学生信息管理</a>
    </div>
    <div>
        <ul class="nav navbar-nav">
            <li class="active"><a href="/home">首页</a></li>
            <li ><a href="home/user">班主任</a></li>
            <li><a href="home/graph">图形区</a></li>
            <li><a href="home/add">添加学生</a></li>
        </ul>
    </div>
    <div class="navbar-right">
        <ul class="nav navbar-nav">
            <li><a href="#">当前班主任：</a></li>
            <li><a href="#">{{request.session.name}}</a></li>
            <li><a href="/home/outlogin">注销</a></li>
        </ul>
    </div>
    </div>
</nav>
<!--主要内容 -->
<div class="panel panel-info">
    <div class="panel-heading">
        <div class="panel-title text-center">
            所有学生信息
        </div>
    </div>
    <div class="panel-body">
      <table id="tr"  width="150px" class="table table-bordered table-hover text-center">
    <tr class="">
        <th>学号</th>
        <th>学生姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>班级</th>
        <th>操作</th>
    </tr>
	</table>
    </div>
    <div class="panel-footer text-right">
        版权所有&copy;踏雪无痕
    </div>
</div>
</body>

<script>
function myFunction(){
	var x;
	var r=confirm("你确定删除吗？");
	if (r==true){
		return true;
	}
	else{
		return false;
	}
}
    $.ajax({
            url:"home/select_stu",
            type:"GET",
            {#发送json数据到服务器#}
            dataType :"json",
            {#请求成功回调函数#}
            success:function (data) {

                var html = '';
				for ( var i = 0; i < data.length; i++) {//循环json对象，拼接tr,td的htm
				    var value=data[i].id
                    var k = '/home/delete?id='+value;
                    var rque = '"javascript:return myFunction()"';
				    var j = '/home/modify?id='+value;
                    var del = "<a href="+k+" onclick="+rque+"><button class='btn btn-danger'>删除</button></a>"
                    var alter = "<a href="+j+"><button class='btn btn-success'>更新</button></a>"
					s = "<tr><td>" + data[i].id + "</td><td>" + data[i].name + "</td><td>" +
            data[i].age +"</td><td>" + data[i].sex + "</td><td>" + data[i].grade
                        + "</td><td>"+del+alter+"</td></tr>"
					$('#tr').append(s);
				}
            },
            {#请求失败回调函数#}
            error:function () {
                alert("查询失败")
            }
        });
</script>

</html>
